#include"StdAfx.h"
#include "TTask.h"
void TTask::Start()
{
	if (th == nul)
	{
		th = new boost::thread(boost::bind(&TTask::MainDo, this));
	}
}

void TTask::MainDo()
{
	try
	{
		Do(this);
	}
	catch (...)
	{
	}
	OnFinished(this);
	delete th;
	th = nul;
}

void TTask::Join()
{
	if (th != nul)
	{
		th->join();
	}
}

void TTask::Report(int _arg)
{
	now = _arg;
	OnPrograss(this);
}

void TTask::Release()
{
	if (th != nul)
	{
		th->interrupt();
		th->join();
		delete th;
		th = nul;
	}
}

TTask::TTask()
{
	th = nul;
}

TTask::TTask(IEventBase<TTask*>* _func)
{
	th = nul;
	Do += _func;
}